package com.app.bimo.commonbusiness.view;


import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.airbnb.lottie.LottieAnimationView;
import com.app.bimo.commonbusiness.R;
import com.app.bimo.commonbusiness.util.SystemUtil;


/**
 * 描述：各种弹出框
 * 作者：limo on 16/6/2 17:26
 */
public class DialogUtil {

    /**
     * 分享  用于 分享app
     *
     * @param context
     */

    public static Dialog initLoadingDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.view_prograss_dialog);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        localLayoutParams.gravity = Gravity.CENTER;
        LottieAnimationView lottieAnimationView = shareDialog.findViewById(R.id.lottieAnimationView);
        lottieAnimationView.setImageAssetsFolder("images");
        lottieAnimationView.setAnimation("loading.json");
        lottieAnimationView.loop(true);
        lottieAnimationView.playAnimation();
        shareDialog.getWindow().setAttributes(localLayoutParams);
        return shareDialog;
    }

    /**
     * 阅读页面整页loading
     *
     * @param context
     */
    public static Dialog initPageLoadingDialog(Context context, int color) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.DialogRadiuStyle);
        shareDialog.setContentView(R.layout.view_prograss_page_loading_dialog);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        localLayoutParams.gravity = Gravity.CENTER;
        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        localLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        LottieAnimationView lottieAnimationView = shareDialog.findViewById(R.id.lottieAnimationView);
        lottieAnimationView.setImageAssetsFolder("images");
        lottieAnimationView.setAnimation("loading.json");
        lottieAnimationView.loop(true);
        lottieAnimationView.playAnimation();
        shareDialog.getWindow().setAttributes(localLayoutParams);
        return shareDialog;
    }

    /**
     * 分享  用于 分享app
     *
     * @param context
     */
    public static Dialog initChoosePhoto(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_choose_photo);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = WindowManager.LayoutParams.MATCH_PARENT;
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.BOTTOM;

        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);

        return shareDialog;
    }

    /**
     * 分享  用于 分享app
     *
     * @param context
     */
    public static Dialog initPayDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_pay);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = WindowManager.LayoutParams.MATCH_PARENT;
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.BOTTOM;
//        localLayoutParams.x = 0;

        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);

        return shareDialog;
    }

    /**
     * @param context
     */
    public static Dialog initADDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_ad);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = WindowManager.LayoutParams.MATCH_PARENT;
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
//        localLayoutParams.x = 0;

        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);

        return shareDialog;
    }

    /**
     * 分享  用于 分享app
     *
     * @param context
     */
    public static Dialog initVipPayDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_vip_pay);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = WindowManager.LayoutParams.MATCH_PARENT;
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.BOTTOM;
//        localLayoutParams.x = 0;

        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);

        return shareDialog;
    }

    /**
     * 安装权限设置弹窗
     *
     * @param context
     * @return
     */
    public static Dialog initInstallDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.DialogRadiuStyle);
        shareDialog.setContentView(R.layout.dialog_install_apk);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        localLayoutParams.width = SystemUtil.getWidth(context) - SystemUtil.dip2px(context, 35 * 2);
        localLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        shareDialog.getWindow().setAttributes(localLayoutParams);
        shareDialog.setCanceledOnTouchOutside(true);
        return shareDialog;

    }

    /**
     * 安装权限设置弹窗
     *
     * @param context
     * @return
     */
    public static Dialog initReplyDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_reply);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        localLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.BOTTOM;
        shareDialog.getWindow().setAttributes(localLayoutParams);
        shareDialog.setCanceledOnTouchOutside(true);
        String temps = "遵守<font color='#38A6FE'>" + "《xx评论区服务协议》" + "</font>营造良好阅读氛围";
        ((TextView) shareDialog.findViewById(R.id.commentHint)).setText(Html.fromHtml(temps));
        EditText editText = shareDialog.findViewById(R.id.edit);
        shareDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                editText.setText("");
            }
        });
        return shareDialog;

    }

    /**
     * 评论详情页面评论弹窗
     *
     * @param context
     * @return
     */
    public static Dialog initCommentDetailReplyDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle);
        shareDialog.setContentView(R.layout.dialog_commentdetail_reply);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        localLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.BOTTOM;
        shareDialog.getWindow().setAttributes(localLayoutParams);
        shareDialog.setCanceledOnTouchOutside(true);
        return shareDialog;

    }

    public static Dialog initBookrackSettingDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_Animation_bg);
        shareDialog.setContentView(R.layout.dialog_bookrack_setting);
        shareDialog.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dismiss();
            }
        });
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        localLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.BOTTOM;
        shareDialog.getWindow().setAttributes(localLayoutParams);
        shareDialog.setCanceledOnTouchOutside(true);

        return shareDialog;

    }


    /**
     * 删除提示弹窗
     *
     * @param context
     */
    public static Dialog initDialogTips(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_tips);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = SystemUtil.getWidth(context) - SystemUtil.dip2px(context, 30 * 2);
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);

        return shareDialog;
    }

    /**
     * 退出详情页面 提示加入书架
     *
     * @param context
     */
    public static Dialog initAddBookrackDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);

        shareDialog.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        shareDialog.getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                        //布局位于状态栏下方
                        View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                        //全屏
                        View.SYSTEM_UI_FLAG_FULLSCREEN |
                        //隐藏导航栏
                        View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
                uiOptions |= 0x00001000;
                shareDialog.getWindow().getDecorView().setSystemUiVisibility(uiOptions);
            }
        });

        shareDialog.setContentView(R.layout.dialog_tips);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = SystemUtil.getWidth(context) - SystemUtil.dip2px(context, 30 * 2);
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);

        return shareDialog;
    }

    /**
     * 分享成功后弹窗
     *
     * @param context
     */
    public static Dialog initShareGifts(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_share);
        shareDialog.findViewById(R.id.shareClose).setOnClickListener(v -> shareDialog.dismiss());

        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = SystemUtil.getWidth(context);
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);

        return shareDialog;
    }

    /**
     * 升级弹窗
     *
     * @param context
     */
    public static Dialog initUpLoadAPP(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_up_loadapp);
        ((TextView) shareDialog.findViewById(R.id.content)).setMovementMethod(ScrollingMovementMethod.getInstance());
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = SystemUtil.getWidth(context) - SystemUtil.dip2px(context, 60);
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);

        return shareDialog;
    }

    /**
     * 获取验证码帮助弹窗
     *
     * @param context
     * @return
     */
    public static Dialog initCodeHelpDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_code_help);
        ((TextView) shareDialog.findViewById(R.id.content)).setMovementMethod(ScrollingMovementMethod.getInstance());
        shareDialog.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dismiss();
            }
        });
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = SystemUtil.getWidth(context) - SystemUtil.dip2px(context, 60);
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);
        return shareDialog;
    }

    /**
     * 权限通知开启弹窗
     *
     * @param context
     * @return
     */
    public static Dialog initNotifyDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_notify_tip);

        shareDialog.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dismiss();
            }
        });
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = SystemUtil.getWidth(context) - SystemUtil.dip2px(context, 60);
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        shareDialog.setCancelable(false);
        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);
        return shareDialog;
    }

    /**
     * 文字下载弹窗
     *
     * @param context
     * @return
     */
    public static Dialog initFontDialogTips(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_down_load);

//        shareDialog.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                shareDialog.dismiss();
//            }
//        });
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = SystemUtil.getWidth(context) - SystemUtil.dip2px(context, 60);
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        shareDialog.setCancelable(false);
        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);
        return shareDialog;
    }

    /**
     * 文字下载进度条弹窗
     *
     * @param context
     * @return
     */
    public static Dialog initFontProgressDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_down_load);

        shareDialog.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dismiss();
            }
        });
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = SystemUtil.getWidth(context) - SystemUtil.dip2px(context, 60);
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        shareDialog.setCancelable(false);
        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);
        return shareDialog;
    }

    /**
     * 文字下载进度条弹窗
     *
     * @param context
     * @return
     */
    public static Dialog initEditNameDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_edit_name);

        shareDialog.findViewById(R.id.cancelBtn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dismiss();
            }
        });
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = SystemUtil.getWidth(context) - SystemUtil.dip2px(context, 60);
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        shareDialog.setCancelable(false);
        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);
        return shareDialog;
    }

    /**
     * 文字下载进度条弹窗
     *
     * @param context
     * @return
     */
    public static Dialog initBindingPhoneDialog(Context context) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_binding_phone);
//        shareDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
//                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = SystemUtil.getWidth(context) - SystemUtil.dip2px(context, 60);
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        shareDialog.setCancelable(false);
        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);
        return shareDialog;
    }

    /**
     * @param context
     * @return
     */
    public static Dialog initAdVideoDialog(Context context, String title, String lbtn, String rbtn) {
        Dialog shareDialog;
        shareDialog = new Dialog(context, R.style.MyDialogStyle_bg);
        shareDialog.setContentView(R.layout.dialog_ad_video);
        ((TextView) shareDialog.findViewById(R.id.title)).setText(title);
        ((TextView) shareDialog.findViewById(R.id.cancleBtn)).setText(lbtn);
        ((TextView) shareDialog.findViewById(R.id.subBtn)).setText(rbtn);
        WindowManager.LayoutParams localLayoutParams = shareDialog.getWindow()
                .getAttributes();
        int w = SystemUtil.getWidth(context) - SystemUtil.dip2px(context, 60);
        int h = WindowManager.LayoutParams.WRAP_CONTENT;
        localLayoutParams.gravity = Gravity.CENTER;
        shareDialog.setCancelable(false);
        localLayoutParams.width = w;
        localLayoutParams.height = h;
        shareDialog.getWindow().setAttributes(localLayoutParams);
        return shareDialog;
    }


}
